-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add key action support in multi-edit mode #48
base: main
Are you sure you want to change the base?
Add key action support in multi-edit mode #48
Conversation
…yAction to set currentEntry left and right border, along with chinese translation
@RibosomeK sorry for the late response. We are going to do 2 things here.
Please check the following template. fun getUpdatedEntriesByKeyAction(
action: KeyAction,
appConf: AppConf,
labelerConf: LabelerConf,
): Pair<List<EntryInPixel>, Int>? {
val paramIndex = when (action) {
KeyAction.SetValue1 -> 0
KeyAction.SetValue2 -> 1
KeyAction.SetValue3 -> 2
KeyAction.SetValue4 -> 3
KeyAction.SetValue5 -> 4
KeyAction.SetValue6 -> 5
KeyAction.SetValue7 -> 6
KeyAction.SetValue8 -> 7
KeyAction.SetValue9 -> 8
KeyAction.SetValue10 -> 9
else -> null
}
if (paramIndex != null) {
return getUpdatedEntriesBySetParameterKeyAction(paramIndex, appConf, labelerConf)
}
val isCursorSnapRightSide = when (action) {
KeyAction.SnapClosestLeftParameter -> false
KeyAction.SnapClosestRightParameter -> true
else -> null
}
if (isCursorAction) {
return getUpdatedEntriesByCursorSnapKeyAction(isCursorSnapRightSide, appConf, labelerConf)
}
return null
}
private fun getUpdatedEntriesBySetParameterKeyAction(
paramIndex: Int,
appConf: AppConf,
labelerConf: LabelerConf,
): Pair<List<EntryInPixel>, Int>? {
// remove this -> Only used in single edit mode
// remove this -> if (entries.size != 1) return null
val fieldCount = this.labelerConf.fields.filter { it.shortcutIndex != null }.size
val pointIndex = when {
// TODO: Update the point index supporting multiple entries
paramIndex == 0 -> MarkerCursorState.START_POINT_INDEX
paramIndex == fieldCount + 1 -> MarkerCursorState.END_POINT_INDEX
paramIndex <= fieldCount -> this.labelerConf.fields.indexOfFirst { it.shortcutIndex == paramIndex }
.takeIf { it >= 0 } ?: return null
else -> return null
}
val cursorPosition = cursorState.value.position ?: return null
val lockDrag = appConf.editor.lockedSettingParameterWithCursor &&
when (appConf.editor.lockedDrag) {
AppConf.Editor.LockedDrag.UseLabeler -> {
val lockedDragByBaseField =
labelerConf.lockedDrag.useDragBase &&
labelerConf.fields.getOrNull(pointIndex)?.dragBase == true
val lockedDragByStart =
labelerConf.lockedDrag.useStart && pointIndex == MarkerCursorState.START_POINT_INDEX
lockedDragByBaseField || lockedDragByStart
}
AppConf.Editor.LockedDrag.UseStart -> pointIndex == MarkerCursorState.START_POINT_INDEX
else -> false
}
val entries = if (lockDrag) {
getLockedDraggedEntries(pointIndex, cursorPosition, forcedDrag = false)
// TODO: for multiple mode, we might need to return all `pointIndex`es that are actually affected by the locked drag
// instead of the current `pointIndex`. so we may need to change the function signature, and update corresponding usages of the return value in `fun MarkerState.editEntryIfNeeded` in `Marker.kt`
} else {
getDraggedEntries(pointIndex, cursorPosition, forcedDrag = false)
}
return entries to pointIndex
}
private fun getUpdatedEntriesByCursorSnapKeyAction(
isRightSide: Boolean,
appConf: AppConf,
labelerConf: LabelerConf,
): Pair<List<EntryInPixel>, Int>? {
// TODO: implement this
// can be similar to `getUpdatedEntriesBySetParameterKeyAction` but
// 1. `pointIndex` is decided by the `cursorPosition`
// 2. `lockDrag` is always `false`, because we don't want to move other parameters at the same time here. This is to say, `appConf.editor.lockedSettingParameterWithCursor` should not affect this new feature.
} |
Hi, in this PR, I add two feature for multi-edit mode, as well as its chinese translation.
First is SetValue1-2 key actions support. Under multi-edit mode, value 1 is the first parameter on the left of the cursor, value 2 is the same but on the right.
The second one is two extra key actions for setting left and right parameter of current entry. But unfortunately, there is bug in getting newest
currentIndex
value, and I dont't know how to fix that. Can you help me on solving this problem?